package com._520it.crm.service.impl;

public class TheadLocalTest2 {
    ThreadLocal<Long> longLocal = new ThreadLocal<Long>(){
    	protected Long initialValue() {
    		return Thread.currentThread().getId();
    	};
    };
    ThreadLocal<String> stringLocal = new ThreadLocal<String>(){
    	protected String initialValue() {
    		return Thread.currentThread().getName();
    	};
    };
 
     
    public long getLong() {
        return longLocal.get();
    }
     
    public String getString() {
        return stringLocal.get();
    }
     
    public static void main(String[] args) throws InterruptedException {
        final TheadLocalTest2 test = new TheadLocalTest2();
         
         
        System.out.println("theadId: " + test.getLong());
        System.out.println("theadName: " + test.getString());
     
         
        Thread thread1 = new Thread(){
            public void run() {
                System.out.println("theadId: " + test.getLong());
                System.out.println("theadName: " + test.getString());
            };
        };
        thread1.start();
        thread1.join();
         
        System.out.println("theadId: " + test.getLong());
        System.out.println("theadName: " + test.getString());
    }
}
